<?php
include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Smarty.class.php");					//--> out template
include_once("Operation.php");						//--> Operation
require_once("controlHeader.php");					//--> system control header
include_once("Message.php");						//--> Message
include_once("Users.php");							//--> user
include_once("UserGroup.php");						//--> User Group
require_once("../tools/fckeditor/fckeditor.php") ;

$objOperate 	= new Operation($objSession->getLanguage());		//--> Operation
$objMessage		= new Message($uid);								//--> Message
$objUserGroup 	= new UserGroup($objSession->getLanguage(), $uid);	//--> User Group
$objUser 		= new Users($uid);									//--> user

$error_message 	= '';
$name			= '';
$level			= 'info';

if(isset($_POST['acceptType']))
	$acceptType = $_POST['acceptType'];
else
	$acceptType 	= 'admin';	

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);
if(isset($_POST['Submit'])){
	$acceptType	= $_POST['acceptType'];
	$accept		= $_POST['accept'];
	$title		= $_POST['title'];
	$content	= $_POST['content'];
	$level		= $_POST['level'];
	
		
	if(empty($title))
		$error_message = 'title should\'t be empty.';
	else if (empty($content))
		$error_message = 'content should\'t be empty.';
	else{
		$isReturn = $objMessage->add($arrOperate, $uid, $accept, $acceptType, $title, $content, $level, $_SERVER['REMOTE_ADDR']);
		if($isReturn)
			$error_message = 'add successfully.';
		else 
			$error_message = 'add failure.';
	}
}

if($acceptType == 'all'){
	$arrAccept = array('0' => "All");
}else if($acceptType == 'admin'){
	$arrAccept = array('0' => "Admin");
}else if($acceptType == 'group'){
	$arrAccept = $objUserGroup->arrGetGroupList($gid);
}else if($acceptType == 'user'){
	$arrAccept = $objUser->arrGetUserList();
}

/*----- load FCKEditor -----*/
$oFCKeditor = new FCKeditor('content') ;

$oFCKeditor->Height		= 600;
$oFCKeditor->BasePath	= FCKeditor_BASE_PATH;

$oFCKeditor->Value = $content;

$fckHtml = $oFCKeditor->CreateHtml() ;

$arrAcceptType 	= array('all' => "All", 'admin' => "Admin", 'group' => "User Group", 'user' => "User");
$arrLevel 		= array('info' => "Normal", 'warn' => "Importance");

/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = CACHE_SYS_DIR;
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('backurl',$backurl);
$smarty->assign('error_message', $error_message);

$smarty->assign('arrAcceptType', $arrAcceptType);
$smarty->assign('acceptTypeS', $acceptType);

$smarty->assign('arrAccept', $arrAccept);
$smarty->assign('accept', $accept);

$smarty->assign('arrLevel', $arrLevel);
$smarty->assign('levelS', $level);

$smarty->assign('title', $title);
$smarty->assign("fckHtml", $fckHtml);

$smarty->display('listMessage_Add.htm');
?>
